package sis.util;

import java.util.Random;

public class PasswordGenerator {

	private String password;
	public static final int LOW_END_PASSWORD_CHAR = 48;
	public static final int HIGH_END_PASSWORD_CHAR = 122;
	private static final int PASSWORD_LENGTH = 8;
	private Random random = new Random();
	
	public String generatePassword() {
		StringBuilder builder = new StringBuilder(PASSWORD_LENGTH);
		for(int i = 0; i < PASSWORD_LENGTH; i++) {
			builder.append(this.getRandomChar());
		}
		return builder.toString();
	}
	
	public String getPassword() {
		return password;
	}

	private char getRandomChar() {
		final char max = HIGH_END_PASSWORD_CHAR - LOW_END_PASSWORD_CHAR;
		return (char)(random.nextInt(max) + LOW_END_PASSWORD_CHAR);
	}

	public void setRandom(Random random) {
		this.random = random;
	}


}
